package com.icinfo.cloud.provider.common.enums;

import cn.hutool.core.util.StrUtil;
import com.icinfo.cloud.provider.common.exception.BusinessException;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.util.ObjectUtils;

/**
 * 描述：文书种类枚举
 *
 */
@AllArgsConstructor
public enum DocumentKindEnum {
    /**
     * 文书种类枚举
     */
    DOC_KIND_BYCFJDS("BYCFJDS", "不予处罚决定书"),
    DOC_KIND_BYCFJDSPB("BYCFJDSPB", "不予处罚决定审批表"),
    DOC_KIND_CFGZS("CFGZS", "处罚告知书"),
    DOC_KIND_CFGZSPB("CFGZSPB", "处罚告知审批表"),
    DOC_KIND_CFGZSTZL("CFGZSTZL", "处罚（听证类）告知书"),
    DOC_KIND_DK2BYXZCFGZS("DK2BYXZCFGZS","不予行政处罚告知书"),
    DOC_KIND_CFJDS("CFJDS", "行政处罚决定书"),
    DOC_KIND_CFJDSPB("CFJDSPB", "行政处罚决定审批表"),
    DOC_KIND_CQYQSQB("CQYQSQB", "呈请延期审批表"),
    DOC_KIND_CQZZQZZXSQB("CQZZQZZXSQB", "呈请中止强制执行审批表"),
    DOC_KIND_CXLASQB("CXLASQB", "撤销立案审批表"),
    DOC_KIND_CYQZTZS("CYQZTZS", "抽样取证通知书"),
    DOC_KIND_CYQZWPCLTZS("CYQZWPCLTZS", "抽样取证物品处理通知书"),
    DOC_KIND_GZSHZ("GZSHZ", "告知书回执"),
    DOC_KIND_JABG("JABG", "案件结案报告"),
    DOC_KIND_JCXXDJBCZJTZS("JCXXDJBCZJTZS", "解除先行登记保存证据通知书"),
    DOC_KIND_JDYJGZS("JDYJGZS", "鉴定意见告知书"),
    DOC_KIND_JTYA("JTYA", "集体议案"),
    DOC_KIND_LASPB("LASPB", "立案审批表"),
    DOC_KIND_QZZXSQS("QZZXSQS", "强制执行申请书"),
    DOC_KIND_SDDZQRS("SDDZQRS", "送达方式及地址确认书"),
    DOC_KIND_SDHZ("SDHZ", "送达回证"),
    DOC_KIND_SQWTS("SQWTS", "委托授权书"),
    DOC_KIND_XWTZS("XWTZS", "询问通知书"),
    DOC_KIND_XZDJBCZJTZS("XZDJBCZJTZS", "先行登记保存证据通知书"),
    DOC_KIND_XZJDLXCGS("XZJDLXCGS", "行政决定履行催告书"),
    DOC_KIND_ZJBG("ZJBG", "案件调查终结报告"),
    DOC_KIND_ZLGZTZS("ZLGZTZS", "责令改正通知书"),
    DOC_KIND_ZLTZWFXWJDS("ZLTZWFXWJDS", "责令停止违法行为决定书"),
    DOC_KIND_ZLTZWFXWTZS("ZLTZWFXWTZS", "责令停止违法行为通知书"),
    DOC_KIND_ZXQKHCJL("ZXQKHCJL", "执行情况核查记录"),
    DOC_KIND_ZZSQB("ZZSQB", "终止审批表"),
    DOC_KIND_JYCXCFJDS("JYCXCFJDS", "简易程序处罚决定书"),
    DOC_KIND_JYCXGAWTCFJDS("JYCXGAWTCFJDS", "简易程序公安委托执法处罚决定书"),
    DOC_KIND_XCZPJSM("XCZPJSM", "现场照片及说明"),
    DOC_KIND_DK2SJCXGZS("DK2SJCXGZS","速结程序同意告知书"),
    DOC_KIND_DK2LJDLXJDS("DK2LJDLXJDS","立即代履行决定书"),
    DOC_KIND_DK2XZQZZXXCBL("DK2XZQZZXXCBL","行政强制执行现场笔录"),
    DOC_KIND_DK1BZGZSPB("DK1BZGZSPB","补正/更正审批表"),
    DOC_KIND_DK2BZGZTZS("DK2BZGZTZS","补正/更正通知书"),
    DOC_KIND_XZCFCXSPB("XZCFCXSPB", "行政处罚撤销审批表"),
    DOC_KIND_XZCFCXJDS("XZCFCXJDS", "行政处罚撤销决定书"),
    DOC_KIND_DK2FQCSSBSM("DK2FQCSSBSM", "放弃陈述、申辩声明");

    /**
     * 编码
     */
    @Getter
    private String code;
    /**
     * 描述
     */
    @Getter
    private String des;

    /**
     * 描述：根据code获取value
     *
     * @param code 编码
     * @return 描述内容
     * @author xiangyuyu
     * @date 2022-02-22 10:43
     */
    public static String getValueByCode(String code) {
        if (ObjectUtils.isEmpty(code)) {
            return null;
        }
        for (DocumentKindEnum e : DocumentKindEnum.values()) {
            if (code.equals(e.getCode())) {
                return e.getDes();
            }
        }
        return null;
    }

    /**
     * 转换枚举类
     *
     * @param code
     * @return
     */
    public static DocumentKindEnum parseByCode(String code) {
        if (ObjectUtils.isEmpty(code)) {
            throw new BusinessException("文书类型不能为空");
        }
        for (DocumentKindEnum e : DocumentKindEnum.values()) {
            if (code.equals(e.getCode())) {
                return e;
            }
        }
        throw new BusinessException(String.format("没有找到对应的文书种类[%s]", code));
    }

    /**
     * 描述：校验code是否是合法枚举
     *
     * @param code 枚举code
     * @return boolean 是否合法枚举（true-是/false-否）
     * @author xiangyuyu
     * @date 2022-02-22 10:42
     */
    public static boolean isLegalEnumCode(String code) {
        boolean flag = false;
        for (DocumentKindEnum e : DocumentKindEnum.values()) {
            if (e.getCode().equalsIgnoreCase(code)) {
                flag = true;
                break;
            }
        }
        return flag;
    }

    public static DocumentKindEnum getEnumByCode(String code) {
        if (StrUtil.isBlank(code)) {
            return null;
        }
        for (DocumentKindEnum e : DocumentKindEnum.values()) {
            if (e.getCode().equalsIgnoreCase(code)) {
                return e;
            }
        }
        return null;
    }
}
